package  com.rboat.exam.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rboat.common.annotation.Log;
import com.rboat.common.enums.BusinessType;
import com.rboat.exam.domain.ExamTestPaperUser;
import com.rboat.exam.service.IExamTestPaperUserService;
import com.rboat.common.core.controller.BaseController;
import com.rboat.common.core.domain.AjaxResult;
import com.rboat.common.utils.poi.ExcelUtil;
import com.rboat.common.core.page.TableDataInfo;

/**
 * 试卷考生Controller
 * 
 * @author rboat
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/exam/user")
public class ExamTestPaperUserController extends BaseController
{
    private String prefix = "exam/user";

    @Autowired
    private IExamTestPaperUserService examTestPaperUserService;

    @RequiresPermissions("exam:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询试卷考生列表
     */
    @RequiresPermissions("exam:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamTestPaperUser examTestPaperUser)
    {
        startPage();
        List<ExamTestPaperUser> list = examTestPaperUserService.selectExamTestPaperUserList(examTestPaperUser);
        return getDataTable(list);
    }

    /**
     * 导出试卷考生列表
     */
    @RequiresPermissions("exam:user:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamTestPaperUser examTestPaperUser)
    {
        List<ExamTestPaperUser> list = examTestPaperUserService.selectExamTestPaperUserList(examTestPaperUser);
        ExcelUtil<ExamTestPaperUser> util = new ExcelUtil<ExamTestPaperUser>(ExamTestPaperUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增试卷考生
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷考生
     */
    @RequiresPermissions("exam:user:add")
    @Log(title = "试卷考生", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamTestPaperUser examTestPaperUser)
    {
        return toAjax(examTestPaperUserService.insertExamTestPaperUser(examTestPaperUser));
    }

    /**
     * 修改试卷考生
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ExamTestPaperUser examTestPaperUser = examTestPaperUserService.selectExamTestPaperUserById(id);
        mmap.put("examTestPaperUser", examTestPaperUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷考生
     */
    @RequiresPermissions("exam:user:edit")
    @Log(title = "试卷考生", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamTestPaperUser examTestPaperUser)
    {
        return toAjax(examTestPaperUserService.updateExamTestPaperUser(examTestPaperUser));
    }

    /**
     * 删除试卷考生
     */
    @RequiresPermissions("exam:user:remove")
    @Log(title = "试卷考生", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examTestPaperUserService.deleteExamTestPaperUserByIds(ids));
    }
}
